feat(widget): expose solana transactions as hex for external providers#545
Conversation
|
📝 WalkthroughWalkthroughAdds ChangesSolana Transaction Normalization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
a8a83fd to
429faec
Compare
Move Solana transaction decoding into shared domain helpers and convert base64 payloads to hex before forwarding them to external wallet providers. Hex-encoded transactions are preserved in hex form so providers receive a consistent encoding.
429faec to
9b1b0eb
Compare
|
This pull request is automatically being deployed by Amplify Hosting (learn more). |
|
This pull request is automatically being deployed by Amplify Hosting (learn more). |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/widget/src/domain/types/transaction.ts`:
- Around line 136-162: The transaction decoding logic in
decodeSolanaTransactionToBuffer and isSolanaHexTransaction is too permissive
because any even-length hex-looking string is auto-treated as hex, which can
misdecode valid base64 payloads. Tighten the detection contract so hex is only
chosen with an explicit prefix like 0x, or add a safe fallback path that tries
base64 when hex is ambiguous or cannot be deserialized. Keep the change
localized to the helpers in transaction.ts and preserve the returned
SolanaTransactionBytes encoding/buffer shape.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9ba7e272-6bf3-4bac-98f5-c8af22a1743c
📒 Files selected for processing (5)
packages/widget/src/domain/types/transaction.tspackages/widget/src/providers/misc/solana-connector.tspackages/widget/src/providers/sk-wallet/index.tsxpackages/widget/tests/use-cases/sk-wallet.test.tsxpackages/widget/tests/use-cases/solana-connector.test.ts
| const isSolanaHexTransaction = (tx: DecodedSolanaTransaction): boolean => { | ||
| const withoutHexPrefix = stripSolanaHexPrefix(tx.trim()); | ||
|
|
||
| return ( | ||
| withoutHexPrefix.length > 0 && | ||
| withoutHexPrefix.length % 2 === 0 && | ||
| solanaHexStringRegex.test(withoutHexPrefix) | ||
| ); | ||
| }; | ||
|
|
||
| export const decodeSolanaTransactionToBuffer = ( | ||
| tx: DecodedSolanaTransaction | ||
| ): SolanaTransactionBytes => { | ||
| const normalizedTx = tx.trim(); | ||
| const withoutHexPrefix = stripSolanaHexPrefix(normalizedTx); | ||
|
|
||
| if (isSolanaHexTransaction(normalizedTx)) { | ||
| return { | ||
| encoding: "hex", | ||
| buffer: Buffer.from(withoutHexPrefix, "hex"), | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| encoding: "base64", | ||
| buffer: Buffer.from(normalizedTx, "base64"), | ||
| }; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Resolve ambiguous unprefixed base64-vs-hex payloads.
Line 152 makes any even-length hex-only string decode as hex, but those strings can also be valid base64 text. That changes the decoded bytes before both Solana deserialization and external-provider normalization. Prefer an explicit contract, e.g. require 0x for hex auto-detection, or reintroduce a base64 fallback when hex decoding cannot deserialize.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/widget/src/domain/types/transaction.ts` around lines 136 - 162, The
transaction decoding logic in decodeSolanaTransactionToBuffer and
isSolanaHexTransaction is too permissive because any even-length hex-looking
string is auto-treated as hex, which can misdecode valid base64 payloads.
Tighten the detection contract so hex is only chosen with an explicit prefix
like 0x, or add a safe fallback path that tries base64 when hex is ambiguous or
cannot be deserialized. Keep the change localized to the helpers in
transaction.ts and preserve the returned SolanaTransactionBytes encoding/buffer
shape.
Move Solana transaction decoding into shared domain helpers and convert base64 payloads to hex before forwarding them to external wallet providers. Hex-encoded transactions are preserved in hex form so providers receive a consistent encoding.
Summary by CodeRabbit
Bug Fixes
Tests